import { connect } from 'umi';
import React, { useRef } from 'react';
import UpdateCancelModal from './UpdateCancelModal';
import { useExpertsManage } from '../common/useExpertsManage';
import { SchemaManage } from '@/components/SchemaComponent';
import { BatchImportModal } from '@/components/BatchImportModal';
import { ExportModal } from './ExportModal';

const ExpertsManageView: React.FC<ExpertsManageAPI.IManageType> = ({ curRes, locationProps }) => {
  /**
   * 管理页组件ref
   * */
  const schemaExpertsManageRef: any = useRef();

  /**
   * 管理页hooks
   * */
  const {
    cancelForm,
    tableProps,
    searchProps,
    actionList,
    batchImport,
    isShowCancel,
    exportState,
    cancelSubmit,
    setBatchImport,
    setIsShowCancel,
    expertsManageRun,
    setExportState,
    exportSearchParams,
    selectRows,
    selectedRowKeys,
  } = useExpertsManage(curRes, locationProps);

  return (
    <>
      {/* 管理页组件 */}
      <SchemaManage ref={schemaExpertsManageRef} searchProps={searchProps} actionList={actionList} tableProps={tableProps} />
      {/* 作废弹窗 */}
      {isShowCancel && <UpdateCancelModal form={cancelForm} onClose={setIsShowCancel} onSubmit={cancelSubmit} />}
      {/* 导入文件弹窗 */}
      {batchImport && (
        <BatchImportModal
          curRes={curRes}
          modalTitle={'批量导入专家'}
          onClose={() => setBatchImport(false)}
          templateUrl={'/expertInfoController/downloadFile'}
          parserImportUrl={'/expertInfoController/import'}
          batchImportUrl={'/expertInfoController/batchImportExpert'}
          refreshCallback={() => expertsManageRun({})}
          filePath={'/minfile/purchase/template/专家信息导入模板.xlsm'}
        />
      )}
      {/* 导出文件弹窗 */}
      {exportState && <ExportModal onClose={() => setExportState(false)} searchParams={exportSearchParams} selectedRowKeys={selectedRowKeys} />}
    </>
  );
};

export default connect(({ baseLogin, navTab }: Record<string, any>) => ({
  curRes: baseLogin?.permissions,
  navTab,
}))(ExpertsManageView);
